*Mihaly Fazekas
*BECSLeseK, aBRaK
*************************************************************************************************
* EHA ANALYSIS
global DIR "d:\Munka\Quality of lawmaking\en-fr-hu-uk comparative_2015\data\"
use "${DIR}qualityoflegislation_EHA_160228_monthly.dta"


***Table 2 (OLD)
tab ia_all source if source!=2
tab ia_all source if source!=2, nofreq column
sum fail1 fail3 ia_all gov_parl_share govp_ch partizanship tv_partizanship ln_bpt word_num_th growth0 if source!=2
*fail2 (only 1 at modification months) is used in the regressions but for summary stat fail1 and fail3 are more informative

hist word_num_th
gen lword_num_th=log(word_num_th)
hist lword_num_th
stset smpl_date, id(id_unique) failure(fail2) origin(time publ_date_ym)
stcox gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt ia_all lword_num_th if source==1, vce(robust) baselevels
*slightly better model: INCLUDE LATER

sum publ_date
gen year=year(publ_date)
tab year
stcox gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt ia_all lword_num_th i.year if source==1, vce(robust) baselevels
*slight furthre improvement, although includig year is a bit problematic


*KILEP AZ ELSO MODOSITAS UTAN (SINGLE FAILURE ANALYSIS)
stset smpl_date, id(id_unique) failure(fail2) origin(time publ_date_ym)


***Figure 1
sts graph if source!=2, hazard by(source) saving(fig1.wmf , replace) title("Smoothed hazard estimates of modification" "first modification only")


***TABLE 3 (SURVIVAL ANALYSIS - SINGLE modification) - pooled analysis


stcox i.ia_all i.source if source!=2, vce(robust) base
estimates store m1
outreg2 using "${DIR}table1.xls", replace  eform ctitle(Model 1) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all gov_parl_share govp_ch partizanship#tv_partizanship i.source if source!=2, vce(robust) base
estimates store m2
outreg2 using "${DIR}table1.xls", append  eform ctitle(Model 2) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt word_num_th i.source if source!=2, vce(robust) base
estimates store m3
outreg2 using "${DIR}table1.xls",append eform ctitle(Model 3) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
estimates store m3
outreg2 using "${DIR}table1.xls",append eform ctitle(Model 4) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail
*stcox i.ia_all gov_parl_share c.govp_ch##c.govp_ch partizanship#tv_partizanship ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
*quadratic formulation doesn't improve


*** TABLE 5. POOLED interactions with politics

stcox govp_ch gov_parl_share partizanship#tv_partizanship ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
estimates store m1
outreg2 using "${DIR}table7.xls", replace  eform ctitle(Model 1) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all i.ia_all#c.govp_ch gov_parl_share partizanship#tv_partizanship ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
*great!
estimates store m2
outreg2 using "${DIR}table7.xls", append  eform ctitle(Model 2) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

tab partizanship tv_partizanship
gen partizanship_ch=.
replace partizanship_ch=0 if partizanship==tv_partizanship
replace partizanship_ch=1 if partizanship!=tv_partizanship
replace partizanship_ch=. if partizanship==. | tv_partizanship==.
tab partizanship_ch

stcox i.partizanship_ch gov_parl_share ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
estimates store m3
outreg2 using "${DIR}table7.xls", append  eform ctitle(Model 3) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all##i.partizanship_ch gov_parl_share ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
estimates store m4
outreg2 using "${DIR}table7.xls", append  eform ctitle(Model 4) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail
*stphplot, by(ia_all) plot1(msym(oh)) plot2(msym(th))
stcurve, hazard at1(ia_all=0 partizanship_ch=1) at2(ia_all=1 partizanship_ch=1)
stcurve, hazard at1(ia_all=0 partizanship_ch=0) at2(ia_all=1 partizanship_ch=0)
*super, RIA is most effective when there is a government side change



*** TABLE 4 - country-wise regressions

hist growth0
hist growth0, by(fail2)
xtile growth0_cat=growth0, nq(3)
tabstat growth0, by(growth0_cat) stat(min mean max N)

hist gov_parl_share
hist govp_ch
tab partizanship


*UK
stcox gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt ia_all word_num_th growth0 if source==1, vce(robust) 
*stcox gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt ia_all word_num_th ib3.growth0_cat if source==1, vce(robust) 
*stcox gov_parl_share partizanship#tv_partizanship ln_bpt i.ia_all##c.govp_ch word_num_th growth0 if source==1, vce(robust) base
*stcox govp_ch partizanship#tv_partizanship ln_bpt i.ia_all##c.gov_parl_share word_num_th growth0 if source==1, vce(robust) base
*no improvement
estimates store m1
outreg2 using "${DIR}table2.xls", replace  eform ctitle(UK) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail
stcurve, hazard at1(ia_all=0) at2(ia_all=1) saving(fig2a.gph,replace) title("UK") xtitle("Analysis time: months until modification")


*FR
stcox gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt ia_all word_num_th growth0 if source==3, vce(robust) 
*stcox gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt ia_all word_num_th ib3.growth0_cat if source==3, vce(robust) 
estimates store m2
outreg2 using "${DIR}table2.xls", append  eform ctitle(FR) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail
stcurve, hazard at1(ia_all=0) at2(ia_all=1) saving(fig2b.gph,replace) title("FR") xtitle("Analysis time: months until modification")

stcox gov_parl_share govp_ch partizanship#tv_partizanship ia_all word_num_th growth0 if source==3, vce(robust)
outreg2 using "${DIR}table2.xls", append  eform ctitle(FR 2.) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label


*HU
stcox gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt ia_all word_num_th growth0 if source==4, vce(robust) 
*stcox gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt ia_all word_num_th ib3.growth0_cat if source==4, vce(robust) 
*growth works nicely
estimates store m3
outreg2 using "${DIR}table2.xls",append eform ctitle(HU) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail
stcurve, hazard at1(ia_all=0) at2(ia_all=1) saving(fig2c.gph,replace) title("HU") xtitle("Analysis time: months until modification")


*IT
stcox gov_parl_share govp_ch partizanship#tv_partizanship  ln_bpt ia_all word_num_th growth0 if source==5, vce(robust)
*stcox gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt ia_all word_num_th ib3.growth0_cat if source==5, vce(robust) 
estimates store m4
outreg2 using "${DIR}table2.xls",append eform ctitle(IT) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail
*Figure 3d
stcurve, hazard at1(ia_all=0) at2(ia_all=1) saving(fig2d.gph,replace) title("IT") xtitle("Analysis time: months until modification")

graph combine fig2a.gph fig2b.gph fig2c.gph fig2d.gph, col(2) xcommon title("Estimated hazard functions by RIA, first modifications") saving(fig2.wmf,replace)

********************************************************************************************************************************************************



***TABLE 5 multiple modifications - pooled

*NEM LEP KI AZ ELSO MODOSITAS UTAN (MULTIPLE FAILURE ANALYSIS)
stset smpl_date, id(id_unique) failure(fail2) origin(time publ_date_ym)  exit( time .)

stcox i.ia_all i.source if source!=2, vce(robust) base
estimates store m1
outreg2 using "${DIR}table5.xls", replace  eform ctitle(Model 1) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all gov_parl_share govp_ch partizanship#tv_partizanship i.source if source!=2, vce(robust) base
estimates store m2
outreg2 using "${DIR}table5.xls", append  eform ctitle(Model 2) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt word_num_th i.source if source!=2, vce(robust) base
estimates store m3
outreg2 using "${DIR}table5.xls",append eform ctitle(Model 3) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
estimates store m3
outreg2 using "${DIR}table5.xls",append eform ctitle(Model 4) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail


***TABLE 6 multiple modifications - country wise

*UK
stcox gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt ia_all word_num_th growth0 if source==1, vce(robust) 
estimates store m1
outreg2 using "${DIR}table6.xls", replace  eform ctitle(UK) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail
stcurve, hazard saving(fig4a.gph,replace) title("UK") xtitle("Analysis time: months until modification")

*FR
stcox gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt ia_all word_num_th growth0 if source==3, vce(robust) 
estimates store m2
outreg2 using "${DIR}table6.xls", append  eform ctitle(FR) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail
stcurve, hazard saving(fig4b.gph,replace) title("FR") xtitle("Analysis time: months until modification")

stcox gov_parl_share govp_ch partizanship#tv_partizanship ia_all word_num_th growth0   if source==3, vce(robust) 
outreg2 using "${DIR}table6.xls", append  eform ctitle(FR 2.) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
stcurve, hazard

*HU
stcox gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt ia_all word_num_th growth0  if source==4, vce(robust) 
estimates store m3
outreg2 using "${DIR}table6.xls",append eform ctitle(HU) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail
stcurve, hazard saving(fig4c.gph,replace) title("HU") xtitle("Analysis time: months until modification")

*IT
stcox gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt ia_all word_num_th growth0 if source==5, vce(robust) 
estimates store m4
outreg2 using "${DIR}table6.xls",append eform ctitle(IT) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail
stcurve, hazard saving(fig4d.gph,replace) title("IT") xtitle("Analysis time: months until modification")

graph combine fig4a.gph fig4b.gph fig4c.gph fig4d.gph, col(2) xcommon title("Estimated hazard functions, multiple modifications") saving(fig4.wmf,replace)

sts graph if source!=2, hazard by(source) saving(fig3.wmf, replace) title("Smoothed hazard estimates of modification" "multiple modifications")




***** R&R 2021 July *****



***** adding new ideology variables *****



use "D:\Munka\Quality of lawmaking\en-fr-hu-uk comparative_2015\data\IdeologyData.dta", clear

drop X

gen date2=substr(Date, 1, 7)
gen smpl_date = monthly(date2, "YM")
format smpl_date %tm

drop date2
drop Date

duplicates drop smpl_date, force

save "D:\Munka\Quality of lawmaking\en-fr-hu-uk comparative_2015\data\IdeologyData_my.dta", replace


use "D:\Munka\Quality of lawmaking\en-fr-hu-uk comparative_2015\data\qualityoflegislation_EHA_160228_monthly.dta", clear

merge m:1 smpl_date using "D:\Munka\Quality of lawmaking\en-fr-hu-uk comparative_2015\data\IdeologyData_my.dta"
drop _merge

label list source

gen gov_conflict=.
replace gov_conflict=UK_Gov_Conflict if source==1
replace gov_conflict=FR_Gov_Conflict if source==3
replace gov_conflict=HU_Gov_Conflict if source==4
replace gov_conflict=IT_Gov_Conflict if source==5
tab gov_conflict
tab gov_conflict source

gen parl_conflict=.
replace parl_conflict=UK_Parl_Conflict if source==1
replace parl_conflict=FR_Parl_Conflict if source==3
replace parl_conflict=HU_Parl_Conflict if source==4
replace parl_conflict=IT_Parl_Conflict if source==5
tab parl_conflict
tab parl_conflict source
tab parl_conflict gov_conflict

save "D:\Munka\Quality of lawmaking\en-fr-hu-uk comparative_2015\data\qualityoflegislation_EHA_160228_monthly.dta", replace



use "D:\Munka\Quality of lawmaking\en-fr-hu-uk comparative_2015\data\IdeologyDataExtended.dta", clear

gen date2=substr(Date, 1, 7)
gen smpl_date = monthly(date2, "YM")
format smpl_date %tm

drop date2
drop Date

duplicates drop smpl_date, force

save "D:\Munka\Quality of lawmaking\en-fr-hu-uk comparative_2015\data\IdeologyDataExtended_my.dta", replace


use "D:\Munka\Quality of lawmaking\en-fr-hu-uk comparative_2015\data\qualityoflegislation_EHA_160228_monthly.dta", clear

merge m:1 smpl_date using "D:\Munka\Quality of lawmaking\en-fr-hu-uk comparative_2015\data\IdeologyDataExtended_my.dta"
drop _merge

drop UKGovConflict UKParlConflict FRGovConflict FRParlConflict ITGovConflict ITParlConflict HUGovConflict HUParlConflict

gen gov_ideology=.
replace gov_ideology=UKCoalitionIdealogy if source==1
replace gov_ideology=FRCoalitionIdeology if source==3
replace gov_ideology=HUCoalitionIdeology if source==4
replace gov_ideology=ITCoalitionIdeology if source==5
tab gov_ideology
tab gov_ideology source


egen gov_ideology_orig=first(gov_ideology), by(id_unique)
gen gov_ideology_diff=gov_ideology-gov_ideology_orig
sum gov_ideology_diff
hist gov_ideology_diff
tab gov_ideology_diff
tab gov_ideology_diff source

gen govid_diff_cat=.
replace govid_diff_cat=0 if gov_ideology_diff<-3 & gov_ideology_diff!=.
replace govid_diff_cat=1 if gov_ideology_diff>=-3 & gov_ideology_diff<0 & gov_ideology_diff!=.
replace govid_diff_cat=2 if gov_ideology_diff==0
replace govid_diff_cat=3 if gov_ideology_diff>0 & gov_ideology_diff<2 & gov_ideology_diff!=.
replace govid_diff_cat=4 if gov_ideology_diff>3 & gov_ideology_diff!=.
tab govid_diff_cat

gen gov_ideology_adiff=abs(gov_ideology_diff)
sum gov_ideology_adiff
hist gov_ideology_adiff

gen govid_diff_cat3=govid_diff_cat
replace govid_diff_cat3=0 if govid_diff_cat==1
replace govid_diff_cat3=1 if govid_diff_cat==2
replace govid_diff_cat3=2 if govid_diff_cat==3
replace govid_diff_cat3=2 if govid_diff_cat==4
tab govid_diff_cat3
tab govid_diff_cat3 govid_diff_cat

gen govid_diff_cat32=govid_diff_cat
replace govid_diff_cat32=1 if govid_diff_cat==1
replace govid_diff_cat32=1 if govid_diff_cat==2
replace govid_diff_cat32=1 if govid_diff_cat==3
replace govid_diff_cat32=2 if govid_diff_cat==4
tab govid_diff_cat32 govid_diff_cat

tab coal_pn, missing

gen coal_bi=coal_pn
replace coal_bi=0 if coal_pn==1
replace coal_bi=1 if coal_pn>1 & coal_pn!=.
tab coal_bi

save "D:\Munka\Quality of lawmaking\en-fr-hu-uk comparative_2015\data\qualityoflegislation_EHA_210722_monthly.dta", replace


***MOD Table 2

sum fail1 fail3 ia_all gov_parl_share govp_ch gov_ideology_diff i.govid_diff_cat3 partizanship_ch gov_conflict coal_bi ln_bpt word_num_th growth0 if source!=2
*fail2 (only 1 at modification months) is used in the regressions but for summary stat fail1 and fail3 are more informative
tab govid_diff_cat3 if source!=2

***MOD Table 3 (First modification) - pooled analysis

tab coal_bi
sum gov_conflict parl_conflict
tab partizanship tv_partizanship
sum gov_ideology_diff gov_ideology_adiff
tabstat govp_ch, by(govid_diff_cat) stat(mean min max N)

sum ia_all i.partizanship_ch gov_parl_share govp_ch gov_conflict coal_bi ln_bpt word_num_th growth0 source if source!=2 
tab ia_all source if source!=2
tab ia_all source if source!=2, column

stset smpl_date, id(id_unique) failure(fail2) origin(time publ_date_ym)

stcox i.ia_all i.source if source!=2, vce(robust) base
estimates store m1
outreg2 using "${DIR}table3.xls", replace  eform ctitle(Model 1) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share govp_ch gov_conflict i.coal_bi i.source if source!=2, vce(robust) base
estimates store m2
outreg2 using "${DIR}table3.xls", append  eform ctitle(Model 2) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share c.govp_ch gov_conflict i.coal_bi ln_bpt word_num_th i.source if source!=2, vce(robust) base
estimates store m3
outreg2 using "${DIR}table3.xls",append eform ctitle(Model 3) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share c.govp_ch gov_conflict i.coal_bi ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
estimates store m4
outreg2 using "${DIR}table3.xls",append eform ctitle(Model 4) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all c.gov_ideology_diff##c.gov_ideology_diff gov_parl_share c.govp_ch gov_conflict i.coal_bi ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
estimates store m5
outreg2 using "${DIR}table3.xls",append eform ctitle(Model 5) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail


***MOD TABLE 4 multiple modifications - pooled

stset smpl_date, id(id_unique) failure(fail2) origin(time publ_date_ym)  exit( time .)

stcox i.ia_all i.source if source!=2, vce(robust) base
estimates store m1
outreg2 using "${DIR}table4.xls", replace  eform ctitle(Model 1) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share govp_ch gov_conflict i.coal_bi i.source if source!=2, vce(robust) base
estimates store m2
outreg2 using "${DIR}table4.xls", append  eform ctitle(Model 2) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share c.govp_ch gov_conflict i.coal_bi ln_bpt word_num_th i.source if source!=2, vce(robust) base
estimates store m3
outreg2 using "${DIR}table4.xls",append eform ctitle(Model 3) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share c.govp_ch gov_conflict i.coal_bi ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
estimates store m4
outreg2 using "${DIR}table4.xls",append eform ctitle(Model 4) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all c.gov_ideology_diff##c.gov_ideology_diff gov_parl_share c.govp_ch gov_conflict i.coal_bi ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
estimates store m5
outreg2 using "${DIR}table4.xls",append eform ctitle(Model 5) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

*** Figure 2

sts graph if source!=2, hazard by(source) saving(fig2.wmf, replace) title("Smoothed hazard estimates of modification" "multiple modifications")



*** MOD TABLE 5. POOLED interactions with politics

stset smpl_date, id(id_unique) failure(fail2) origin(time publ_date_ym)  exit( time .)

stcox govp_ch gov_parl_share gov_conflict i.coal_bi ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
estimates store m1
outreg2 using "${DIR}table5.xls", replace  eform ctitle(Model 1) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all##c.govp_ch gov_parl_share gov_conflict i.coal_bi ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
estimates store m2
outreg2 using "${DIR}table5.xls", append  eform ctitle(Model 2) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.partizanship_ch gov_parl_share gov_conflict i.coal_bi ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
estimates store m3
outreg2 using "${DIR}table5.xls", append  eform ctitle(Model 3) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all##i.partizanship_ch gov_parl_share gov_conflict i.coal_bi ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
estimates store m4
outreg2 using "${DIR}table5.xls", append  eform ctitle(Model 4) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox ib1.govid_diff_cat3 gov_parl_share gov_conflict i.coal_bi ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
estimates store m5
outreg2 using "${DIR}table5.xls", append  eform ctitle(Model 5) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

stcox i.ia_all##ib1.govid_diff_cat3 gov_parl_share gov_conflict i.coal_bi ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
estimates store m6
outreg2 using "${DIR}table5.xls", append  eform ctitle(Model 6) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label
estat phtest, detail

***MOD figure 3
stcox i.ia_all##i.partizanship_ch gov_parl_share gov_conflict i.coal_bi ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
stcurve, hazard at1(ia_all=0  partizanship_ch=0) at2(ia_all=1  partizanship_ch=0) xtitle("Analysis time: months")
stcurve, hazard at1(ia_all=0  partizanship_ch=1) at2(ia_all=1  partizanship_ch=1) xtitle("Analysis time: months")



***explorations Table 3

stset smpl_date, id(id_unique) failure(fail2) origin(time publ_date_ym)

*alternative ideology change specifications
stcox i.ia_all gov_parl_share govp_ch partizanship#tv_partizanship gov_conflict i.coal_bi i.source if source!=2, vce(robust) base
stcox i.ia_all gov_parl_share govp_ch c.gov_ideology_adiff gov_conflict i.coal_bi i.source if source!=2, vce(robust) base
*gov_ideology_adiff insignificant
stcox i.ia_all gov_parl_share govp_ch ib2.govid_diff_cat gov_conflict i.coal_bi i.source if source!=2, vce(robust) base
stcox i.ia_all gov_parl_share govp_ch ib1.govid_diff_cat3 gov_conflict i.coal_bi i.source if source!=2, vce(robust) base
stcox i.ia_all gov_parl_share govp_ch ib1.govid_diff_cat32 gov_conflict i.coal_bi i.source if source!=2, vce(robust) base

stcox i.ia_all gov_parl_share govp_ch c.gov_ideology_diff##c.gov_ideology_diff gov_conflict i.coal_bi i.source if source!=2, vce(robust) base
pwcorr gov_ideology_diff govp_ch gov_parl_share
stcox i.ia_all gov_parl_share c.govp_ch##ib2.govid_diff_cat gov_conflict i.coal_bi ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
*mostly insignificant

*non-linear ideology change effect
stcox i.ia_all gov_parl_share govp_ch c.gov_ideology_diff##c.gov_ideology_diff gov_conflict i.coal_bi i.source if source!=2, vce(robust) base
margins, at(gov_ideology_diff=(-3.5(0.5)3.5))
marginsplot, x(gov_ideology_diff) recast(line) recastci(rarea) xlabel(-3.5(0.5)3.5)

stcox i.ia_all gov_parl_share govp_ch c.gov_ideology_diff##c.gov_ideology_diff gov_conflict i.coal_bi i.source if source!=2 & gov_ideology_diff<3, vce(robust) base
margins, at(gov_ideology_diff=(-3.5(0.5)3.5))
marginsplot, x(gov_ideology_diff) recast(line) recastci(rarea) xlabel(-3.5(0.5)3.5)



***explorations Table 5

tab partizanship_ch govid_diff_cat

stset smpl_date, id(id_unique) failure(fail2) origin(time publ_date_ym)  exit( time .)

stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share govp_ch gov_conflict i.coal_bi ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
stcox i.ia_all##c.gov_ideology_diff##c.gov_ideology_diff gov_parl_share gov_conflict i.coal_bi ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
margins, at(gov_ideology_diff=(-3.5(0.5)3.5) ia_all=(0 1))
marginsplot, x(gov_ideology_diff) recast(line) recastci(rarea) xlabel(-3.5(1)3.5)


sum govp_ch
stcox i.ia_all##c.govp_ch gov_parl_share gov_conflict i.coal_bi ln_bpt word_num_th growth0 i.source if source!=2, vce(robust) base
margins, at(govp_ch=(-20(10)20) ia_all=(0 1))
marginsplot, x(govp_ch) recast(line) recastci(rarea) xlabel(-20(10)20)


***** Appendix


*** TABLE A2 first modifiction - country-wise regressions

stset smpl_date, id(id_unique) failure(fail2) origin(time publ_date_ym)

*FR
stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share govp_ch gov_conflict i.coal_bi ln_bpt word_num_th growth0 if source==3, vce(robust) 
*stcox gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt ia_all word_num_th ib3.growth0_cat if source==3, vce(robust) 
estimates store m2
outreg2 using "${DIR}tablea2.xls", append  eform ctitle(FR) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label

stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share govp_ch gov_conflict i.coal_bi word_num_th growth0 if source==3, vce(robust)
outreg2 using "${DIR}tablea2.xls", append  eform ctitle(FR 2.) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label

*HU
stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share govp_ch gov_conflict i.coal_bi ln_bpt word_num_th growth0 if source==4, vce(robust) 
*stcox gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt ia_all word_num_th ib3.growth0_cat if source==4, vce(robust) 
*growth works nicely
estimates store m3
outreg2 using "${DIR}tablea2.xls", append eform ctitle(HU) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label

*IT
stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share govp_ch gov_conflict i.coal_bi ln_bpt word_num_th growth0 if source==5, vce(robust)
*stcox gov_parl_share govp_ch partizanship#tv_partizanship ln_bpt ia_all word_num_th ib3.growth0_cat if source==5, vce(robust) 
estimates store m4
outreg2 using "${DIR}tablea2.xls", append eform ctitle(IT) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label

*UK
stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share govp_ch gov_conflict i.coal_bi ln_bpt word_num_th growth0 if source!=2, vce(robust) base
stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share govp_ch gov_conflict i.coal_bi ln_bpt word_num_th growth0 if source==1, vce(robust) 
estimates store m1
outreg2 using "${DIR}tablea2.xls", append  eform ctitle(UK) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label


***TABLE A3 multiple modifications - country wise


stset smpl_date, id(id_unique) failure(fail2) origin(time publ_date_ym)  exit( time .)

*FR
stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share govp_ch gov_conflict i.coal_bi ln_bpt word_num_th growth0 if source==3, vce(robust) 
estimates store m2
outreg2 using "${DIR}tablea3.xls", append  eform ctitle(FR) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label

stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share govp_ch gov_conflict i.coal_bi word_num_th growth0 if source==3, vce(robust) 
outreg2 using "${DIR}tablea3.xls", append  eform ctitle(FR 2.) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label

*HU
stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share govp_ch gov_conflict i.coal_bi ln_bpt word_num_th growth0 if source==4, vce(robust) 
estimates store m3
outreg2 using "${DIR}tablea3.xls", append eform ctitle(HU) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label

*IT
stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share govp_ch gov_conflict i.coal_bi ln_bpt word_num_th growth0 if source==5, vce(robust) 
estimates store m4
outreg2 using "${DIR}tablea3.xls", append eform ctitle(IT) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label

*UK
stcox i.ia_all ib1.govid_diff_cat3 gov_parl_share govp_ch gov_conflict i.coal_bi ln_bpt word_num_th growth0 if source==1, vce(robust) 
estimates store m1
outreg2 using "${DIR}tablea3.xls", append  eform ctitle(UK) addstat(Number of subjects, `e(N_sub)', Number of failures, `e(N_fail)', Pseudo R^2,`e(r2_p)') label



***** replication material preparaition

use "D:\Munka\Quality of lawmaking\en-fr-hu-uk comparative_2015\data\qualityoflegislation_EHA_210722_monthly.dta", clear


*drop irrelevant country

drop if source==2

*select relevant variables

keep smpl_date id_unique publ_date_ym fail1 fail2 fail3 ///
ia_all gov_ideology_diff gov_parl_share govp_ch govid_diff_cat3 partizanship_ch gov_conflict coal_bi ln_bpt word_num_th growth0 source

*label variables

lab var publ_date_ym "publication date: year-month"
lab var fail1 "Modification: 0 before 1st modification, 1 afterwards"
lab var fail2 "Modification: 0 when there is no modification, 1 when there is a modification"
lab var fail3 "Modification: Cummulative number of modifications at the time"
lab var gov_ideology_diff "Government ideology change (abs. left-right score change)"
lab var gov_parl_share "Share of largest governing party in parliament at enactment (% of seats)"
lab var govp_ch "Government power change (% of seats change)"
lab var govid_diff_cat3 "Government ideology change (categorical)"
lab var partizanship_ch "Partisanship change (change=1)"
lab var gov_conflict "Government ideology conflict (abs. left-right score)"
lab var coal_bi "coalition government (1) or not (0)"
lab var ln_bpt "Log time in parliament (log(number of days))"
lab var word_num_th "Word count of the law (1000s)"


save "D:\Munka\Quality of lawmaking\en-fr-hu-uk comparative_2015\data\qualityoflegislation_monthly.dta", replace


